package com.pingan.haofang.searchcloud.api.query.parser.dbobject.util;

import com.pingan.haofang.searchcloud.api.query.parser.dbobject.Condition;
import com.pingan.haofang.searchcloud.api.query.parser.dbobject.Operator;
import com.pingan.haofang.searchcloud.api.query.parser.dbobject.SqlNode;
import com.pingan.haofang.searchcloud.api.query.parser.dbobject.SqlNodeType;
import com.pingan.haofang.searchcloud.api.query.parser.dbobject.sqlnode.ColumnNode;

/**
 * ClassName: ConditionOptimizer <br>
 * Function: 条件优化器
 *
 * @author luyi
 * @version 1.0.0
 * @since 1.0.0
 * @date 20151002
 */
public class ConditionOptimizer {

    /**
     * 优化condition，主要是为了调整顺序，将左侧置为column
     * 
     * @param condition
     */
    public static void optimizeCondition(Condition condition) {
        SqlNode right = condition.getRightList().get(0);
        if (right.getType() == SqlNodeType.COLUMN) {
            SqlNode temp = condition.getLeft();
            condition.setLeft((ColumnNode) right);
            condition.setRight(temp);
            condition.setOperator(Operator.getReverse(condition.getOperator()));
        }
    }

}
